home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / buttons / btndmo / form1.frm < prev    next >
Text File  |  1995-10-01  |  8KB  |  261 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Button Demo"
  4.    ClientHeight    =   4890
  5.    ClientLeft      =   1110
  6.    ClientTop       =   1515
  7.    ClientWidth     =   5640
  8.    Height          =   5295
  9.    Left            =   1050
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4890
  12.    ScaleWidth      =   5640
  13.    Top             =   1170
  14.    Width           =   5760
  15.    Begin VB.PictureBox Picture1 
  16.       BackColor       =   &H00FFFF00&
  17.       Height          =   495
  18.       Index           =   4
  19.       Left            =   60
  20.       ScaleHeight     =   435
  21.       ScaleWidth      =   2295
  22.       TabIndex        =   4
  23.       Top             =   2580
  24.       Width           =   2355
  25.    End
  26.    Begin VB.PictureBox Picture1 
  27.       BackColor       =   &H00FFFF00&
  28.       Height          =   495
  29.       Index           =   3
  30.       Left            =   60
  31.       ScaleHeight     =   435
  32.       ScaleWidth      =   2295
  33.       TabIndex        =   3
  34.       Top             =   1920
  35.       Width           =   2355
  36.    End
  37.    Begin VB.PictureBox Picture1 
  38.       BackColor       =   &H00FFFF00&
  39.       Height          =   495
  40.       Index           =   2
  41.       Left            =   60
  42.       ScaleHeight     =   435
  43.       ScaleWidth      =   2295
  44.       TabIndex        =   2
  45.       Top             =   1260
  46.       Width           =   2355
  47.    End
  48.    Begin VB.PictureBox Picture1 
  49.       BackColor       =   &H00FFFF00&
  50.       Height          =   495
  51.       Index           =   1
  52.       Left            =   60
  53.       ScaleHeight     =   435
  54.       ScaleWidth      =   2295
  55.       TabIndex        =   1
  56.       Top             =   660
  57.       Width           =   2355
  58.    End
  59.    Begin VB.CommandButton Command2 
  60.       Caption         =   "Appearance"
  61.       Height          =   375
  62.       Left            =   540
  63.       TabIndex        =   5
  64.       Top             =   3240
  65.       Width           =   1215
  66.    End
  67.    Begin VB.PictureBox Picture1 
  68.       BackColor       =   &H00FFFF00&
  69.       Height          =   495
  70.       Index           =   0
  71.       Left            =   60
  72.       ScaleHeight     =   435
  73.       ScaleWidth      =   2295
  74.       TabIndex        =   0
  75.       Top             =   60
  76.       Width           =   2355
  77.    End
  78.    Begin VB.Label Label2 
  79.       AutoSize        =   -1  'True
  80.       Caption         =   $"FORM1.frx":0000
  81.       Height          =   975
  82.       Index           =   3
  83.       Left            =   2520
  84.       TabIndex        =   10
  85.       Top             =   3720
  86.       Width           =   3015
  87.       WordWrap        =   -1  'True
  88.    End
  89.    Begin VB.Label Label2 
  90.       AutoSize        =   -1  'True
  91.       Caption         =   $"FORM1.frx":00AD
  92.       Height          =   1170
  93.       Index           =   2
  94.       Left            =   2520
  95.       TabIndex        =   9
  96.       Top             =   2400
  97.       Width           =   2985
  98.       WordWrap        =   -1  'True
  99.    End
  100.    Begin VB.Label Label2 
  101.       AutoSize        =   -1  'True
  102.       Caption         =   $"FORM1.frx":0188
  103.       Height          =   975
  104.       Index           =   1
  105.       Left            =   2520
  106.       TabIndex        =   8
  107.       Top             =   1260
  108.       Width           =   2970
  109.       WordWrap        =   -1  'True
  110.    End
  111.    Begin VB.Label Label2 
  112.       AutoSize        =   -1  'True
  113.       Caption         =   $"FORM1.frx":0251
  114.       Height          =   780
  115.       Index           =   0
  116.       Left            =   2520
  117.       TabIndex        =   7
  118.       Top             =   300
  119.       Width           =   3135
  120.       WordWrap        =   -1  'True
  121.    End
  122.    Begin VB.Label Label1 
  123.       AutoSize        =   -1  'True
  124.       BackStyle       =   0  'Transparent
  125.       Caption         =   "NOTES:"
  126.       Height          =   195
  127.       Left            =   2520
  128.       TabIndex        =   6
  129.       Top             =   60
  130.       Width           =   600
  131.    End
  132. End
  133. Attribute VB_Name = "Form1"
  134. Attribute VB_Creatable = False
  135. Attribute VB_Exposed = False
  136. Option Explicit
  137. 'The class array is dimensioned to the
  138. 'the same size as the picturebox control
  139. 'array used as containers for the buttons.
  140. Private clsButtons(4) As New CButtons
  141.  
  142. Private Sub Command2_Click()
  143.     Static Index
  144.     Const BTN_FLAT = 1
  145.     Const BTN_3D = 2
  146.     
  147.     'By using a static variable we can
  148.     'change the appearance property of the
  149.     'button classes separately, in sequence
  150.     'every time the user presses this button
  151.     
  152.     If clsButtons(Index).Appearance = 1 Then
  153.         clsButtons(Index).Appearance() = BTN_3D
  154.     Else
  155.         clsButtons(Index).Appearance() = BTN_FLAT
  156.     End If
  157.     
  158.     If Index = UBound(clsButtons) Then
  159.         Index = 0
  160.     Else
  161.         Index = Index + 1
  162.     End If
  163. End Sub
  164.  
  165. Private Sub Form_Load()
  166.     Dim i%
  167.     'The button class contains its own 'Custom' initialzation
  168.     'procedure.  This is necessary because the vb default
  169.     'implementation of the Class_Initialize event does not allow
  170.     'for the passing of parameters.
  171.     
  172.     'We need to pass the container to the class during
  173.     'initialzation.  This is because the class assigns
  174.     'the picturebox to a private picturebox variable; which
  175.     'it references throughout the class code making the
  176.     'code itself generic/internal to the class and allows
  177.     'for portability between vb apps.
  178.     
  179.     'Once the picturebox is assigned, then we can use all
  180.     'the features of the class.  The default number of buttons
  181.     'is one; in this demo we assign an incrementing number
  182.     'to demonstrate the flexibility of the Buttons property.
  183.     'As shown in the loop, the picturebox is first assigned,
  184.     'then the number of buttons is set.
  185.     
  186.     For i% = LBound(clsButtons) To UBound(clsButtons)
  187.         Call clsButtons(i%).InitializeClass(Picture1(i%))
  188.         clsButtons(i%).Buttons() = i + 2
  189.     Next i%
  190.     
  191.     'Center the form
  192.     Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
  193. End Sub
  194.  
  195.  
  196. Private Sub Form_Unload(Cancel As Integer)
  197.     Dim i%
  198.     'This is required for design mode in VB to
  199.     'force the class to terminate when the form
  200.     'is unloaded
  201.     For i% = LBound(clsButtons) To UBound(clsButtons)
  202.         Set clsButtons(i%) = Nothing
  203.     Next i%
  204. End Sub
  205.  
  206.  
  207. Private Sub Picture1_DblClick(Index As Integer)
  208.     'Some users prefer the option to allow no buttons
  209.     'to be selected.  This can easily be achieved by
  210.     'setting the Value property to zero.  For this
  211.     'example, I allow the user to do this by double
  212.     'clicking anywhere on the container.
  213.     
  214.     clsButtons(Index).Value() = 0
  215. End Sub
  216.  
  217. Private Sub Picture1_GotFocus(Index As Integer)
  218.     'The buttons need to be redrawn to update
  219.     'the button images to show that the container
  220.     '(i.e. the buttons) now have the focus
  221.     
  222.     Call clsButtons(Index).Refresh
  223. End Sub
  224.  
  225. Private Sub Picture1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
  226.     'The button class subclasses this event.
  227.     
  228.     'In this demo, the class implements the functionality
  229.     'of the direction keys as per a normal option button
  230.     'group.
  231.     
  232.     Call clsButtons(Index).KeyDown(KeyCode, Shift)
  233. End Sub
  234.  
  235.  
  236. Private Sub Picture1_LostFocus(Index As Integer)
  237.     'The buttons need to be redrawn to update
  238.     'the button images to show that the container
  239.     '(i.e. the buttons) does not have the focus
  240.     
  241.     Call clsButtons(Index).Refresh
  242. End Sub
  243.  
  244.  
  245. Private Sub Picture1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  246.     'The button class subclasses this event.
  247.     
  248.     'In this demo, the class checks for mousehits on
  249.     'the buttons and changes focus/value to the button
  250.     'that is hit.
  251.     
  252.     Call clsButtons(Index).MouseDown(Button, Shift, X, Y)
  253. End Sub
  254.  
  255. Private Sub Picture1_Paint(Index As Integer)
  256.     'Redraw the buttons
  257.     Call clsButtons(Index).Refresh
  258. End Sub
  259.  
  260.  
  261.